package com.sky.controller.admin;

import com.sky.dto.SeckillVoucherDTO;
import com.sky.entity.SeckillVoucher;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.VoucherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: invictusQAQ
 * @Date: 2023-09-06-16:11
 * @Description: 代金券管理接口
 */
@RestController
@Slf4j
@RequestMapping("/admin/voucher")
@Api(tags = "代金券管理接口")
public class VoucherController {

    @Autowired
    private VoucherService voucherService;

    /**
     * 新增秒杀券
     *
     * @param seckillVoucher
     * @return
     */
    @PostMapping
    @ApiOperation("新增秒杀券")
    public Result<Long> save(@RequestBody SeckillVoucher seckillVoucher){
        voucherService.addSeckillVoucher(seckillVoucher);
        return Result.success(seckillVoucher.getId());
    }

    @GetMapping("/page")
    @ApiOperation("秒杀券分页查询")
    //Get方式不需要加 @RequestBody
    //SeckillVoucherDTO LocalDateTime属性需要@DateTimeFormat格式化
    //自定义拓展消息转换器仅支持@RequestBody
    public Result<PageResult> page(SeckillVoucherDTO seckillVoucherDTO){
        PageResult pageResult=voucherService.pageQuery(seckillVoucherDTO);
        return Result.success(pageResult);
    }
}
